package com.hanoi.wiki.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.hanoi.wiki.model.json.UserJson;

@Entity
@Table(name = "USER")
public class User implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public User() {
		
	}
	
	public User(UserJson json) {
		this.userName 		= json.getUserName();
		this.right 			= json.getRight();
		this.password 		= json.getPassword();
		this.description	= json.getDescription();
		this.status 		= json.getStatus();
	}
	
	@Id	
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "ID")
	private Integer id;

	@Column(name = "USER_NAME", length = 50, unique = true, nullable = false)
	private String userName;

	@Column(name = "USER_PASSWORD", length = 32, nullable = false)
	private String password;

	@Column(name = "RIGHTS", length = 2000)
	private String right;

	@Column(name = "DESCRIPTION", length = 2000)
	private String description;

	@Column(name = "USER_STATUS")
	private Integer status;

	@OneToOne(mappedBy="user", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private UserEvaluation userEvaluation;

	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	private List<UserStatistic> userStatistic;

	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	private List<UserLog> userLog;
	
	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private Role role;
	
	public UserEvaluation getUserEvaluation() {
		return userEvaluation;
	}	
	public void setUserEvaluation(UserEvaluation userEvaluation) {
		this.userEvaluation = userEvaluation;
	}
	public List<UserStatistic> getUserStatistic() {
		return userStatistic;
	}
	public void setUserStatistic(List<UserStatistic> userStatistic) {
		this.userStatistic = userStatistic;
	}	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getRight() {
		return right;
	}
	public void setRight(String right) {
		this.right = right;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	public List<UserLog> getUserLog() {
		return userLog;
	}
	public void setUserLog(List<UserLog> userLog) {
		this.userLog = userLog;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

}
